package com.tuandai.commons.encrypt;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by chenpi on 2017/3/1.
 */
public class RsaSecretEncryptorFactory {

    /**
     * 获取加解密器
     * @param location
     * @param password
     * @param alias
     * @param secret
     * @return
     */
    public static RsaSecretEncryptor getRsaSecretEncryptor(String location,String password,String alias,String secret){
        ClassPathResource resource = new ClassPathResource(location);
        KeyStoreKeyFactory keyFactory =new KeyStoreKeyFactory(resource, password.toCharArray());
        KeyStoreTextEncryptorLocator locator = new KeyStoreTextEncryptorLocator(keyFactory, secret,alias);
        Map<String,String> keys = new LinkedHashMap<>();
        keys.put("name", "application");
        keys.put("profiles", "default");
        return locator.locate(keys);
    }
}
